package com.brave.edu.manager.service;

import com.brave.edu.manager.dao.TeacherDao;
import com.brave.edu.manager.domian.Teacher;

public class TeacherService {
    private TeacherDao TeacherDao = new TeacherDao();

    public boolean isExists(String id) {
        Teacher[] Teas = TeacherDao.findAllTeacher();
        boolean exists = false;
        for (int i = 0; i < Teas.length; i++) {
            Teacher tea = Teas[i];
            if (tea != null && tea.getId().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public boolean addTeacher(Teacher tea) {
        return TeacherDao.addTeacher(tea);
    }

    public Teacher[] findTeacher() {
        Teacher[] AllTeacher = TeacherDao.findAllTeacher();
        boolean res = false;
        for (int i = 0; i < AllTeacher.length; i++) {
            Teacher tea = AllTeacher[i];
            if (tea != null) {
                res = true;
                break;
            }
        }
        if (res) {
            return AllTeacher;
        } else {
            return null;
        }
    }

    public void deleteTeacherId(String deleId) {
        TeacherDao.deleteTeacherId(deleId);
    }

    public void updateTeacherId(String updateId, Teacher newTea) {
        TeacherDao.updateTeacher(updateId, newTea);
    }
}
